package student.aistar.day05;

import java.util.Date;

public class DateDemo {
    public static void main(String[] args) {
        //1.创建一个日期对象
        Date d = new Date();

        //为什么此处输出的不是内存地址???  -00-  toString()

        System.out.println(d);//Wed Jul 21 08:46:37 CST 2021

        //2.重载的构建方法
        Date d2 = new Date(2021 - 1900, 6, 21);
        System.out.println(d2);

        //3.利用好描述来构建一个Date对象
        Date d3 = new Date(1626829161216L);
        System.out.println(d3);

        //4.获取当前日期毫秒数
        long nowTime = d2.getTime();

        //使用毫秒数获取三天后的日期
        long afterThreeTime = new Date().getTime()+3L*24*60*60*1000;
        System.out.println("三天后时间为: "+new Date(afterThreeTime));


        System.out.println("=========set设置/get获取============");
        Date now = new Date();
        now.setYear(2021);
        now.setMonth(4);
        now.setDate(1);
        System.out.println("now: "+now);
        int year = now.getYear();
        System.out.println("year: "+year);
        int month = now.getMonth();
        System.out.println("month: " + month);//获取月份按0开始
        System.out.println("date: "+now.getDate());//获取几号
        System.out.println("day"+now.getDay());//获取周几

        //没有设置. Date会设置为当前系统时间
        System.out.println("hours: "+now.getHours());


        //void setTime(long date); 和 构造Date(long time); 两个方法设置时间是同理的
        Date dd = new Date();
        dd.setTime(1726830007794L);
        System.out.println(dd);
    }
}
